#include "stonewt.h"
#include <iostream>
using namespace std;
Stonewt::Stonewt(double lbs)
{
	stone = int(lbs) / Lbs_per_stn;
	pds_left = int(lbs) % Lbs_per_stn + lbs - int(lbs);
	pounds = lbs;
	style = Style::POUNDS;
}
Stonewt::Stonewt(int stn, double lbs)
{
	stone = stn;
	pds_left = lbs;
	pounds = stn * Lbs_per_stn + lbs;
	style = Style::FLOATPOUNDS;
}
Stonewt::Stonewt()
{
	stone = pounds = pds_left = 0;
	style = Style::STONE;
}
Stonewt::~Stonewt()
{

}
void Stonewt::show_lbs()const
{
	cout << pounds << " pounds\n";
}
void Stonewt::show_stn()const
{
	cout << stone << " stone, " << pds_left << " pounds\n";
}

void Stonewt::setStyle(Style style)
{
	this->style = style;
}

Stonewt Stonewt::operator+(const Stonewt& s)
{
	Stonewt sum;
	sum.pounds = pounds + s.pounds;
	sum.stone = sum.pounds / Lbs_per_stn;
	sum.pds_left = int(sum.pounds) % Lbs_per_stn + sum.pounds - int(sum.pounds);
	sum.style = this->style;
	return sum;
}

Stonewt Stonewt::operator-(const Stonewt& s)
{
	Stonewt sum;
	sum.pounds = pounds - s.pounds;
	sum.stone = sum.pounds / Lbs_per_stn;
	sum.pds_left = int(sum.pounds) % Lbs_per_stn + sum.pounds - int(sum.pounds);
	sum.style = this->style;
	return sum;
}

Stonewt Stonewt::operator*(int n)
{
	Stonewt sum;
	sum.pounds = pounds * n;
	sum.stone = sum.pounds / Lbs_per_stn;
	sum.pds_left = int(sum.pounds) % Lbs_per_stn + sum.pounds - int(sum.pounds);
	sum.style = this->style;
	return sum;
}

ostream& operator<<(ostream& os, const Stonewt& s)
{
	switch (s.style)
	{
	case Stonewt::STONE:
		os << "stone: " << s.stone + s.pds_left / Stonewt::Lbs_per_stn<<endl;
		break;
	case Stonewt::FLOATPOUNDS:
		os << s.stone << " stone," << s.pds_left << " pounds\n";
		break;
	case Stonewt::POUNDS:
		os << s.pounds << " pounds\n";
		break;
	default:
		break;
	}
	return os;
}
